<%@ page import="javax.naming.InitialContext" %>
<%@ page import="javax.sql.DataSource" %>
<%@ page import="java.sql.Connection" %>
<%@ page import="java.sql.PreparedStatement" %>
<%@ page import="java.sql.ResultSet" %>
<%@ page import="com.bdqn.dao.StuDaoImpl" %>
<%@ page import="com.bdqn.entity.Stu" %>
<%@ page import="java.util.List" %>
<%@ page import="com.bdqn.entity.News" %>
<%@ page import="java.util.ArrayList" %>
<%@ page import="java.util.Map" %>
<%@ page import="java.util.HashMap" %>
<%@ page contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
<!DOCTYPE html>
<html>
<head>
    <title>我的首页</title>
</head>
<body>
<%
    //java代码
    //获取容器
    /*InitialContext context = new InitialContext();
    //容器通过JNDI查找数据源
    DataSource dataSource = (DataSource) context.lookup("java:comp/env/jdbc/news");
    //通过数据源连接池获取连接对象
    Connection connection = dataSource.getConnection();
    out.println(connection);

    //查询数据
    String sql="select * from stu";
    //基于数据库连接对象将SQL字符串预编译为语句
    PreparedStatement ps = connection.prepareStatement(sql);
    //执行语句
    ResultSet resultSet = ps.executeQuery();
    while (resultSet.next()){
        out.println("<p>"+resultSet.getInt(1)+"--"+resultSet.getString(2)+"</p>");
    }*/

    /*StuDaoImpl stuDao=new StuDaoImpl();
    Stu stu = new Stu("Jason","0001","男",1);*/
    //stuDao.delete(11);
    //stuDao.update(stu);
    //stuDao.insert(stu);
    /*List<Stu> list=stuDao.show();
    out.println(list);*/

    //response.sendRedirect("pages/newsDetailList.jsp");
    //重定向
    //response.sendRedirect("jsp/admin/admin.jsp");
%>
<%--转发-->实现页面跳转--%>
<jsp:forward page="jsp/admin/admin.jsp"></jsp:forward>

<%
    News news = new News();
    news.setTitle("嘻嘻哈哈");
    //pageContext页面上下文--页面作用域
    pageContext.setAttribute("news",news);//把新闻对象添加到当前页面作用域里
    List<News> list=new ArrayList<>();
    list.add(news);
    pageContext.setAttribute("list",list);//把对象添加到作用域中
    Map<String,String> map=new HashMap<>();
    map.put("name","张三");
    map.put("pwd","123456");
    pageContext.setAttribute("map",map);

%>
${pageScope.news.title}
<hr>
${sesssion.news["title"]}<%--没有放在作用域中，所以不显示--%>
<hr>
${list[0].title}
<hr>
${3+5}<%--算术运算符--%>
<hr>
${empty news}<%--进行非空判断--%>
<hr>
<a href="index2.jsp?key=admin">链接</a>
<hr>
${map["name"]}----${map["pwd"]}

</body>
</html>